---------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Severity/PredictedValues.log
  log type:  text
 opened on:  12 Nov 2016, 21:35:46

. cd "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Severity";
/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Severity

. **************************************************************;
. *Author: Jeff Carter                                         *;
. *Date: Saturday, May 23, 2015                              *;
. *Purpose: Simulating Predictions                *;
. **************************************************************;
. ** Need Legend for Probabilities and Differences  **;
. use "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Severity/SimData.dta";

. postutil clear;

. postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 prob_hat3 lo3 hi3 prob_hat4 lo4 hi4 prob_hat5 lo5 h
> i5
>                 diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1 diff_hat2 diff_lo2 diff_hi2 
>                 prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21 prob_hat31 lo31 hi31  prob_hat41 lo41 hi41
>  prob_hat51 lo51 hi51
>                 diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11 diff_hat21 diff_lo21 diff_hi21
>                 delta_hat delta_lo delta_hi delta_hat1 delta_lo1 delta_hi1 delta_hat2 delta_lo2 delta_hi2
>                 using PredictedValues, replace;
(note: file PredictedValues.dta not found)

. noisily display "start";
start

. local a=0 ;

. while `a' < 4 { ;
  2. {;
  3. scalar h_Accountable =   0  ;
  4. scalar h_LameDuck= 1  ;
  5. scalar h_Civilian = 0;
  6. scalar h_Military = 1;
  7. scalar h_Constant = 1;
  8. scalar h_Parliament = 0;
  9. scalar h_CivilWar = 0;
 10. scalar h_GDPpc =  12589.35;
 11. scalar h_Growth = 3.453132;
 12. scalar h_MajorPower = 0;
 13. scalar h_Borders = 2;
 14. scalar h_Mobilization =  -.0008714 ;
 15. scalar h_Time = 5;
 16.  scalar h_Rivalry = 0;
 17. scalar h_Female = 0;
 18. generate x_betahat0 = MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 19. generate x_betahat1 = MG_b1* h_LameDuck
>     + MG_b2*`a'
>     + MG_b3*(h_LameDuck*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 20. gen prob0=  1/(1+exp(x_betahat0-MG_b11));
 21. gen prob1=   (1/(1+exp(x_betahat0-MG_b12)))  -  (1/(1+exp(x_betahat0-MG_b11)))  ;
 22. gen prob2=   1- (1/(1+exp(x_betahat0-MG_b12)));
 23. gen prob3=  1/(1+exp(x_betahat1-MG_b11));
 24. gen prob4=  (1/(1+exp(x_betahat1-MG_b12)))  -  (1/(1+exp(x_betahat1-MG_b11)))  ;
 25. gen prob5=   1- (1/(1+exp(x_betahat1-MG_b12)));
 26.         gen diff0=prob3-prob0 ;
 27. gen diff1=prob4-prob1 ;
 28. gen diff2=prob5-prob2 ;
 29.         egen probhat0=mean(prob0) ;
 30. egen probhat1=mean(prob1) ;
 31. egen probhat2=mean(prob2) ;
 32. egen probhat3=mean(prob3) ;
 33. egen probhat4=mean(prob4) ;
 34. egen probhat5=mean(prob5) ;
 35. egen diffhat0=mean(diff0) ;
 36. egen diffhat1=mean(diff1) ;
 37. egen diffhat2=mean(diff2) ;
 38.  generate x_betahat01 =   MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 39.  generate x_betahat11 =   MG_b1* h_LameDuck
>     + MG_b2*`a'
>     + MG_b3*(h_LameDuck*`a')
>     + MG_b4*h_Rivalry
>     + MG_b5*h_Borders
>     + MG_b6*h_Parliament
>     + MG_b7*h_Female 
>     + MG_b8*h_Time 
>     + MG_b9*(h_Time^2)
>     + MG_b10*(h_Time^3);
 40. gen prob01=  1/(1+exp(x_betahat01-MG_b11));
 41. gen prob11=   (1/(1+exp(x_betahat01-MG_b12)))  -  (1/(1+exp(x_betahat01-MG_b11)))  ;
 42. gen prob21=   1- (1/(1+exp(x_betahat01-MG_b12)));
 43. gen prob31=  1/(1+exp(x_betahat11-MG_b11));
 44. gen prob41=  (1/(1+exp(x_betahat11-MG_b12)))  -  (1/(1+exp(x_betahat11-MG_b11)))  ;
 45. gen prob51=   1- (1/(1+exp(x_betahat11-MG_b12)));
 46.         gen diff01=prob31-prob01 ;
 47. gen diff11=prob41-prob11 ;
 48. gen diff21=prob51-prob21 ;
 49.         egen probhat01=mean(prob01) ;
 50. egen probhat11=mean(prob11) ;
 51. egen probhat21=mean(prob21) ;
 52. egen probhat31=mean(prob31) ;
 53. egen probhat41=mean(prob41) ;
 54. egen probhat51=mean(prob51) ;
 55. egen diffhat01=mean(diff01) ;
 56. egen diffhat11=mean(diff11) ;
 57. egen diffhat21=mean(diff21) ;
 58.         gen delta= diff01-diff0 ;
 59. gen delta1 = diff11-diff1 ;
 60. gen delta2 = diff21-diff2 ;
 61. egen deltahat=mean(delta) ;
 62. egen deltahat1=mean(delta1) ;
 63. egen deltahat2=mean(delta2) ;
 64. tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 prob_hat3 lo3 hi3 prob_hat4 lo4 hi4 prob_hat5 lo5 hi5
>         diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1 diff_hat2 diff_lo2 diff_hi2
>         prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21 prob_hat31 lo31 hi31 prob_hat41 lo41 hi41 prob_hat
> 51 lo51 hi51
>         diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11 diff_hat21 diff_lo21 diff_hi21
>         delta_hat delta_lo delta_hi delta_hat1 delta_lo1 delta_hi1 delta_hat2 delta_lo2 delta_hi2;
 65.             _pctile prob0, p(2.5,97.5) ;
 66.     scalar `lo0'=r(r1) ;
 67.     scalar `hi0'=r(r2) ;
 68.     _pctile prob1, p(2.5,97.5) ;
 69.     scalar `lo1'=r(r1) ;
 70.     scalar `hi1'=r(r2) ;
 71.     _pctile prob2, p(2.5,97.5) ;
 72.     scalar `lo2'=r(r1) ;
 73.     scalar `hi2'=r(r2) ;
 74.     _pctile prob3, p(2.5,97.5) ;
 75.     scalar `lo3'=r(r1) ;
 76.     scalar `hi3'=r(r2) ;
 77.     _pctile prob4, p(2.5,97.5) ;
 78.     scalar `lo4'=r(r1) ;
 79.     scalar `hi4'=r(r2) ;
 80.     _pctile prob5, p(2.5,97.5) ;
 81.     scalar `lo5'=r(r1) ;
 82.     scalar `hi5'=r(r2) ;
 83.             _pctile diff0, p(2.5,97.5) ;
 84.     scalar `diff_lo0'= r(r1) ;
 85.     scalar `diff_hi0'=r(r2) ;
 86.     _pctile diff1, p(2.5,97.5) ;
 87.     scalar `diff_lo1'= r(r1) ;
 88.     scalar `diff_hi1'=r(r2) ;
 89.     _pctile diff2, p(2.5,97.5) ;
 90.     scalar `diff_lo2'= r(r1) ;
 91.     scalar `diff_hi2'=r(r2) ;
 92.             scalar `prob_hat0'=probhat0 ;
 93.     scalar `prob_hat1'=probhat1 ;
 94.     scalar `prob_hat2'=probhat2 ;
 95.     scalar `prob_hat3'=probhat3 ;
 96.     scalar `prob_hat4'=probhat4 ;
 97.     scalar `prob_hat5'=probhat5 ;
 98.           scalar `diff_hat0'=diffhat0 ;
 99.     scalar `diff_hat1'=diffhat1 ;
100.     scalar `diff_hat2'=diffhat2 ;
101.     _pctile prob01, p(2.5,97.5) ;
102.     scalar `lo01'=r(r1) ;
103.     scalar `hi01'=r(r2) ;
104.     _pctile prob11, p(2.5,97.5) ;
105.     scalar `lo11'=r(r1) ;
106.     scalar `hi11'=r(r2) ;
107.     _pctile prob21, p(2.5,97.5) ;
108.     scalar `lo21'=r(r1) ;
109.     scalar `hi21'=r(r2) ;
110.     _pctile prob31, p(2.5,97.5) ;
111.     scalar `lo31'=r(r1) ;
112.     scalar `hi31'=r(r2) ;
113.             _pctile prob41, p(2.5,97.5) ;
114.     scalar `lo41'=r(r1) ;
115.     scalar `hi41'=r(r2) ;
116.     _pctile prob51, p(2.5,97.5) ;
117.     scalar `lo51'=r(r1) ;
118.     scalar `hi51'=r(r2) ;
119.             _pctile diff01, p(2.5,97.5) ;
120.     scalar `diff_lo01'= r(r1) ;
121.     scalar `diff_hi01'=r(r2) ;
122.     _pctile diff11, p(2.5,97.5) ;
123.     scalar `diff_lo11'= r(r1) ;
124.     scalar `diff_hi11'=r(r2) ;
125.     _pctile diff21, p(2.5,97.5) ;
126.     scalar `diff_lo21'= r(r1) ;
127.     scalar `diff_hi21'=r(r2) ;
128.     scalar `prob_hat01'=probhat01 ;
129.     scalar `prob_hat11'=probhat11 ;
130.     scalar `prob_hat21'=probhat21 ;
131.     scalar `prob_hat31'=probhat31 ;
132.     scalar `prob_hat41'=probhat41 ;
133.     scalar `prob_hat51'=probhat51 ;
134.     scalar `diff_hat01'=diffhat01 ;
135.     scalar `diff_hat11'=diffhat11 ;
136.     scalar `diff_hat21'=diffhat21 ;
137.     _pctile delta, p(2.5,97.5) ;
138.     scalar `delta_lo'= r(r1) ;
139.     scalar `delta_hi'=r(r2) ;
140.     _pctile delta1, p(2.5,97.5) ;
141.     scalar `delta_lo1'= r(r1) ;
142.     scalar `delta_hi1'=r(r2) ;
143.     _pctile delta2, p(2.5,97.5) ;
144.     scalar `delta_lo2'= r(r1) ;
145.     scalar `delta_hi2'=r(r2) ;
146.             scalar `delta_hat'=deltahat;
147.     scalar `delta_hat1'=deltahat1;
148.     scalar `delta_hat2'=deltahat2;
149.  post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') (`prob_hat2') (`lo2') (`hi2')
>         (`prob_hat3') (`lo3') (`hi3') (`prob_hat4') (`lo4') (`hi4') (`prob_hat5') (`lo5') (`hi5')
>         (`diff_hat0') (`diff_lo0') (`diff_hi0') (`diff_hat1') (`diff_lo1') (`diff_hi1') (`diff_hat2') (`diff_lo2') (`diff
> _hi2')
>         (`prob_hat01') (`lo01') (`hi01') (`prob_hat11') (`lo11') (`hi11') (`prob_hat21') (`lo21') (`hi21')
>         (`prob_hat31') (`lo31') (`hi31') (`prob_hat41') (`lo41') (`hi41') (`prob_hat51') (`lo51') (`hi51')
>         (`diff_hat01') (`diff_lo01') (`diff_hi01') (`diff_hat11') (`diff_lo11') (`diff_hi11') (`diff_hat21') (`diff_lo21'
> ) (`diff_hi21')
>                 (`delta_hat') (`delta_lo') (`delta_hi') (`delta_hat1') (`delta_lo1') (`delta_hi1') (`delta_hat2') (`delta
> _lo2') (`delta_hi2')
> 
>     ;
150.     } ;
151. drop    x_betahat0 x_betahat1
>         prob0 prob1 prob2 prob3 prob4 prob5
>         diff0 diff1 diff2
>         probhat0 probhat1 probhat2 probhat3 probhat4 probhat5
>         diffhat0 diffhat1 diffhat2
>         x_betahat01 x_betahat11
>         prob01 prob11 prob21 prob31 prob41 prob51
>         diff01 diff11 diff21
>         probhat01 probhat11 probhat21 probhat31 probhat41 probhat51
>         diffhat01 diffhat11 diffhat21
>         delta deltahat delta1 deltahat1 delta2 deltahat2;
152.     local a=`a'+ 1 ;
153.     display "." _c ;
154.     } ;
....
. display "" ;


.  postclose mypost ;

. use PredictedValues, clear;

. gen ruler = _n;

. sum;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   prob_hat0 |         4     .926865    .0257406   .8942914   .9537606
         lo0 |         4    .8884794    .0486294   .8232126   .9334874
         hi0 |         4    .9549397    .0114601   .9429594   .9694314
   prob_hat1 |         4    .0559764    .0192672   .0357333   .0802611
         lo1 |         4    .0345302    .0088417   .0233978    .043826
-------------+--------------------------------------------------------
         hi1 |         4    .0850513     .035487   .0517894   .1324158
   prob_hat2 |         4    .0171585     .006475    .010506   .0254475
         lo2 |         4    .0099281     .002617    .006669   .0127293
         hi2 |         4    .0277084    .0132228   .0156684   .0456155
   prob_hat3 |         4    .9693792    .0035524   .9645502   .9725126
-------------+--------------------------------------------------------
         lo3 |         4    .9364988    .0261404   .9006586   .9578159
         hi3 |         4    .9867748    .0042995    .982861   .9921283
   prob_hat4 |         4    .0237275    .0027108   .0213217   .0274038
         lo4 |         4    .0101902    .0032718   .0061318   .0131707
         hi4 |         4    .0492536    .0200984   .0328751   .0769363
-------------+--------------------------------------------------------
   prob_hat5 |         4    .0068933    .0008418   .0061656    .008046
         lo5 |         4    .0028533    .0008889   .0017281   .0036219
         hi5 |         4    .0148145    .0062702   .0098481   .0235265
   diff_hat0 |         4    .0425141    .0222353    .018752   .0702588
    diff_lo0 |         4    .0049849    .0071212  -.0031899   .0121745
-------------+--------------------------------------------------------
    diff_hi0 |         4    .0824648    .0479512   .0383373   .1467724
   diff_hat1 |         4   -.0322489    .0165931  -.0528573  -.0144116
    diff_lo1 |         4   -.0622007    .0351347  -.1091587  -.0296453
    diff_hi1 |         4   -.0038331    .0054711  -.0093911   .0024387
   diff_hat2 |         4   -.0102652    .0056439  -.0174015  -.0043404
-------------+--------------------------------------------------------
    diff_lo2 |         4   -.0207822    .0130251  -.0384605  -.0090822
    diff_hi2 |         4   -.0011676    .0016651  -.0028043   .0007512
  prob_hat01 |         4     .926865    .0257406   .8942914   .9537606
        lo01 |         4    .8884794    .0486294   .8232126   .9334874
        hi01 |         4    .9549397    .0114601   .9429594   .9694314
-------------+--------------------------------------------------------
  prob_hat11 |         4    .0559764    .0192672   .0357333   .0802611
        lo11 |         4    .0345302    .0088417   .0233978    .043826
        hi11 |         4    .0850513     .035487   .0517894   .1324158
  prob_hat21 |         4    .0171585     .006475    .010506   .0254475
        lo21 |         4    .0099281     .002617    .006669   .0127293
-------------+--------------------------------------------------------
        hi21 |         4    .0277084    .0132228   .0156684   .0456155
  prob_hat31 |         4    .9693792    .0035524   .9645502   .9725126
        lo31 |         4    .9364988    .0261404   .9006586   .9578159
        hi31 |         4    .9867748    .0042995    .982861   .9921283
  prob_hat41 |         4    .0237275    .0027108   .0213217   .0274038
-------------+--------------------------------------------------------
        lo41 |         4    .0101902    .0032718   .0061318   .0131707
        hi41 |         4    .0492536    .0200984   .0328751   .0769363
  prob_hat51 |         4    .0068933    .0008418   .0061656    .008046
        lo51 |         4    .0028533    .0008889   .0017281   .0036219
        hi51 |         4    .0148145    .0062702   .0098481   .0235265
-------------+--------------------------------------------------------
  diff_hat01 |         4    .0425141    .0222353    .018752   .0702588
   diff_lo01 |         4    .0049849    .0071212  -.0031899   .0121745
   diff_hi01 |         4    .0824648    .0479512   .0383373   .1467724
  diff_hat11 |         4   -.0322489    .0165931  -.0528573  -.0144116
   diff_lo11 |         4   -.0622007    .0351347  -.1091587  -.0296453
-------------+--------------------------------------------------------
   diff_hi11 |         4   -.0038331    .0054711  -.0093911   .0024387
  diff_hat21 |         4   -.0102652    .0056439  -.0174015  -.0043404
   diff_lo21 |         4   -.0207822    .0130251  -.0384605  -.0090822
   diff_hi21 |         4   -.0011676    .0016651  -.0028043   .0007512
   delta_hat |         4           0           0          0          0
-------------+--------------------------------------------------------
    delta_lo |         4           0           0          0          0
    delta_hi |         4           0           0          0          0
  delta_hat1 |         4           0           0          0          0
   delta_lo1 |         4           0           0          0          0
   delta_hi1 |         4           0           0          0          0
-------------+--------------------------------------------------------
  delta_hat2 |         4           0           0          0          0
   delta_lo2 |         4           0           0          0          0
   delta_hi2 |         4           0           0          0          0
       ruler |         4         2.5    1.290994          1          4

. saveold PredictedValues, replace;
file PredictedValues.dta saved

. log close;
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexTheoretical/Conditional/Severity/PredictedValues.log
  log type:  text
 closed on:  12 Nov 2016, 21:35:47
---------------------------------------------------------------------------------------------------------------------------
